package com.ruoyi.web.controller.business;

import java.util.List;

import com.ruoyi.business.domain.BusContract;
import com.ruoyi.business.service.IBusContractService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusContractCollection;
import com.ruoyi.business.service.IBusContractCollectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同回款Controller
 * 
 * @author ruoyi
 * @date 2021-09-02
 */
@RestController
@RequestMapping("/business/collection")
public class BusContractCollectionController extends BaseController
{
    @Autowired
    private IBusContractCollectionService busContractCollectionService;

    @Autowired
    private IBusContractService busContractService;

    /**
     * 查询合同回款列表
     */
    //@PreAuthorize("@ss.hasPermi('business:collection:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusContractCollection busContractCollection)
    {
        startPage();
        List<BusContractCollection> list = busContractCollectionService.selectBusContractCollectionList(busContractCollection);
        return getDataTable(list);
    }

    /**
     * 导出合同回款列表
     */
   // @PreAuthorize("@ss.hasPermi('business:collection:export')")
    @Log(title = "合同回款", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusContractCollection busContractCollection)
    {
        BusContract busContract = busContractService.selectBusContractByContractId(busContractCollection.getContractId());
        List<BusContractCollection> list = busContractCollectionService.selectBusContractCollectionList(busContractCollection);
        ExcelUtil<BusContractCollection> util = new ExcelUtil<BusContractCollection>(BusContractCollection.class);
        //return util.exportExcel(list, "合同回款数据");
        return util.exportExcel(list, "合同编号【"+busContract.getContractNo()+"】回款信息");
    }

    /**
     * 获取合同回款详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:collection:query')")
    @GetMapping(value = "/{collectionId}")
    public AjaxResult getInfo(@PathVariable("collectionId") Long collectionId)
    {
        return AjaxResult.success(busContractCollectionService.selectBusContractCollectionByCollectionId(collectionId));
    }

    /**
     * 新增合同回款
     */
    //@PreAuthorize("@ss.hasPermi('business:collection:add')")
    @Log(title = "合同回款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusContractCollection busContractCollection)
    {
        busContractCollection.setCreateBy(getUsername());
        return toAjax(busContractCollectionService.insertBusContractCollection(busContractCollection));
    }

    /**
     * 修改合同回款
     */
   //@PreAuthorize("@ss.hasPermi('business:collection:edit')")
    @Log(title = "合同回款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusContractCollection busContractCollection)
    {
        busContractCollection.setUpdateBy(getUsername());
        return toAjax(busContractCollectionService.updateBusContractCollection(busContractCollection));
    }

    /**
     * 删除合同回款
     */
   // @PreAuthorize("@ss.hasPermi('business:collection:remove')")
    @Log(title = "合同回款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{collectionIds}")
    public AjaxResult remove(@PathVariable Long[] collectionIds)
    {
        return toAjax(busContractCollectionService.deleteBusContractCollectionByCollectionIds(collectionIds));
    }
}
